﻿<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>计算属性和方法的区别</title>
    <script src="js/vue.js"></script>
</head>

<body>
    <div id="app">
        <!-- <div>{{changNum()}}</div> -->
        <!-- <div>{{num2}}</div> -->
        <button onclick="fn1()">查看两者的区别</button>
    </div>
    <script>
        var vm = new Vue({
            el: "#app",
            data: {
                num: 9
            },
            methods: {
                changNum() {
                    console.log(new Date());
                    return this.num - 1;
                }
            },
            computed: {
                num2: function () {
                    console.log(new Date());
                    return this.num - 1;
                }
            },
        });
        function fn1(){
            setInterval(() => {
                // console.log(vm.num2);
                console.log(vm.changNum());
            }, 1000);
        }
    </script>
</body>

</html>